package com.ruoyi.project.xkx.student.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.xkx.student.domain.IdAndListId;
import com.ruoyi.project.xkx.student.domain.XkxStudent;
import com.ruoyi.project.xkx.student.service.XkxStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class XkxStudentController {

    @Autowired
    private XkxStudentService xkxStudentService;

    /*
    * 查询正式学员
    * */
    @GetMapping("/formalStu/{current}/{size}")
    public Object getFormalStu(@PathVariable Integer current,@PathVariable Integer size,
                                   Integer schoolId,Integer userId,String studentName,String studentPhone){
       Page page = xkxStudentService.getFormalStu(new Page<XkxStudent>(current,size),schoolId,userId,studentName,studentPhone);

       List<XkxStudent> students = page.getRecords();
       Long count = page.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        map.put("count",count);
        return  map;
    }

    /*
     * 查询意向学员
     * */
    @GetMapping("/intentionStu/{current}/{size}")
    public Object getIntentionStu(@PathVariable Integer current,@PathVariable Integer size,
                               Integer schoolId,Integer userId,String studentName,String studentPhone){
        Page page = xkxStudentService.getIntentionStu(new Page<XkxStudent>(current,size),schoolId,userId,studentName,studentPhone);

        List<XkxStudent> students = page.getRecords();
        Long count = page.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        map.put("count",count);
        return  map;
    }

    /*
     * 到期提醒
     * */
    @GetMapping("/remindStu/{current}/{size}")
    public Object remind(@PathVariable Integer current,@PathVariable Integer size,
                                  Integer schoolId,Integer timeNum,Integer clsHourNum){
        Page page = xkxStudentService.remind(new Page<XkxStudent>(current,size),schoolId,timeNum,clsHourNum);

        List<XkxStudent> students = page.getRecords();
        Long count = page.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        map.put("count",count);
        return  map;
    }

    /*
     * 到期提醒
     * */
    @GetMapping("/bindAdviserError/{current}/{size}")
    public Object bindAdviserError(@PathVariable Integer current,@PathVariable Integer size,
                         Integer schoolId,String studentName,String studentPhone){
        Page page = xkxStudentService.getBindAdviserError(new Page<XkxStudent>(current,size),schoolId,studentName,studentPhone);

        List<XkxStudent> students = page.getRecords();
        Long count = page.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        map.put("count",count);
        return  map;
    }

    /**
     * 新学员注册
     * */
    @PostMapping("/editAdviser")
    public Object editAdviser(@RequestBody IdAndListId idList){

        if(xkxStudentService.editAdviser(idList)){

            return AjaxResult.error(0,"操作成功");
        }
        return AjaxResult.error(-1,"操作失败");
    }


    /**
     * 新学员注册
     * */
    @PostMapping("/register")
    public AjaxResult studentRegister(@RequestBody XkxStudent xkxStudent){
        Date tiem = new Date();
        xkxStudent.setAddTime(tiem);
        if(xkxStudentService.save(xkxStudent)){
            String studentNumber = xkxStudent.getStudentNumber();//根据学生编号查询学生Id返回给前台
            XkxStudent student = xkxStudentService.getStudentByStudentNumber(studentNumber);
            return AjaxResult.error(0,"操作成功",student);
        }
        return AjaxResult.error(-1,"操作失败");
    }

    /**
     *  前台小程序根据课程顾问id查询查询正式学员
     * */
    @GetMapping("/formalStuByUserId")
    public Object formalStuByUserId(Integer userId,String searchData){

        List<XkxStudent> students = xkxStudentService.getFormalStuByUserId(userId,searchData);

        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        return  map;
    }


    /**
     *  前台小程序根据课程顾问id查询查询意向学员
     * */
    @GetMapping("/intentionStuByUserId")
    public Object intentionStuByUserId(Integer userId,String searchData){

        List<XkxStudent> students = xkxStudentService.getIntentionStuByUserId(userId,searchData);

        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        return  map;
    }



    /**
     *  前台小程序根据课程顾问id查询查询学员剩余课时
     * */
    @GetMapping("/remindStuByUserId")
    public Object remindStuByUserId(Integer userId){

        List<XkxStudent> students = xkxStudentService.getRemindStuByUserId(userId);

        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",students);
        return  map;
    }

    /**
     * 前台小程序根据学员id查询正式学员信息
     * */
    @GetMapping("/getOneStudentByStudentId")
    public Object getOneStudentByStudentId(Integer studentId){

        XkxStudent student = xkxStudentService.getOneStudentByStudentId(studentId);

        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",student);
        return  map;
    };


    /**
     * 前台小程序根据学员id查询意向学员信息
     * */
    @GetMapping("/getOneIntentionStuByStudentId")
    public Object getOneIntentionStuByStudentId(Integer studentId){

        XkxStudent student = xkxStudentService.getOneIntentionStuByStudentId(studentId);

        Map<String,Object> map = new HashMap<>();
        map.put("msg","查询成功");
        map.put("code",0);
        map.put("data",student);
        return  map;
    };

}
